package cn.com.jenson.service.system.handler;

import cn.com.jenson.common.Result;
import cn.com.jenson.exception.BusinessException;
import cn.com.jenson.exception.TokenException;
import cn.com.jenson.system.Code;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@ControllerAdvice(annotations = RestController.class)
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(TokenException.class)
    public Result<String> accessException(TokenException e) {
        return Result.fil(Code.TOKEN_ERR, e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result<String> accessException(BusinessException e) {
        return Result.fil(Code.BUSINESS_ERR, e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<String> accessException(Exception e) {
        return Result.fil(Code.SYSTEM_ERR, e.getMessage());
    }
}
